package com.aaa.controller;

import com.aaa.entity.Product;
import com.aaa.service.ProductService;
import com.aaa.util.DefaultMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


@Controller
public class ProductControlle {

    @Autowired
    //引入
    private ProductService productService;
    @RequestMapping("/tolist")
    public String tolist(){
        return "list";
    }
    @RequestMapping("/listAll")
    @ResponseBody
    public List<Product> listAll(){
        List<Product> products=productService.listAll();
        return products;
    }
    @RequestMapping("/tosave")
    public String insert(){

        return "save";
    }
   @RequestMapping("/save")
    public DefaultMsg save(Product product){
        DefaultMsg save=productService.insert(product);
        return save;
   }
   @RequestMapping("/gai1")
    @ResponseBody
    public Product gai1(Product product){
       Product byPid = productService.findByPid(product);
         return byPid;
    }
  @RequestMapping("/toupdate")
    public String update(){
        return "update1";
  }
  @RequestMapping("/update")
    @ResponseBody
    public DefaultMsg update(Product product){
        DefaultMsg update=productService.update(product);
        return  update;
  }
  @RequestMapping("/delete")
    @ResponseBody
    public DefaultMsg delete(Product product){
      DefaultMsg delete = productService.delete(product);
       return delete;
    }
}
